const deepClone = require("../template.js")

/** 4. 特殊对象测试 */
function testSpecial() {
  console.log(
    "4.1 Date对象:",
    (() => {
      const date = new Date("2023-01-01")
      const cloned = deepClone(date)
      return (
        cloned instanceof Date &&
        cloned.getTime() === date.getTime() &&
        cloned !== date
      )
    })()
  )

  console.log(
    "4.2 RegExp对象:",
    (() => {
      const regex = /test/gi
      const cloned = deepClone(regex)
      return (
        cloned instanceof RegExp &&
        cloned.source === regex.source &&
        cloned.flags === regex.flags &&
        cloned !== regex
      )
    })()
  )

  console.log(
    "4.3 函数处理:",
    (() => {
      const obj = {
        fn: function () {
          return "test"
        },
        arrow: () => "arrow"
      }
      const cloned = deepClone(obj)
      return (
        typeof cloned.fn === "function" &&
        typeof cloned.arrow === "function" &&
        cloned !== obj
      )
    })()
  )

  console.log(
    "4.4 Map对象:",
    (() => {
      const map = new Map()
      map.set("key1", "value1")
      map.set("key2", { nested: "value" })
      const cloned = deepClone(map)
      return (
        cloned instanceof Map &&
        cloned.get("key1") === "value1" &&
        cloned !== map
      )
    })()
  )

  console.log(
    "4.5 Set对象:",
    (() => {
      const set = new Set([1, 2, 3, { a: 4 }])
      const cloned = deepClone(set)
      return cloned instanceof Set && cloned.size === set.size && cloned !== set
    })()
  )

  console.log(
    "4.6 包含特殊值的对象:",
    (() => {
      const obj = {
        nan: NaN,
        infinity: Infinity,
        negInfinity: -Infinity,
        symbol: Symbol("test"),
        undef: undefined,
        nullVal: null
      }
      const cloned = deepClone(obj)
      return (
        Object.is(cloned.nan, NaN) &&
        cloned.infinity === Infinity &&
        cloned.negInfinity === -Infinity &&
        cloned !== obj
      )
    })()
  )

  console.log("--------------------")
}

testSpecial()

module.exports = testSpecial
